package com.onesports.intelligent.k12.polarlight.controller.organization.product;

import cn.oneframework.common.domain.dto.IdDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.onesports.framework.kit.common.valid.Json;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.market.ProductInsertDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.market.ProductIsSellDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.market.ProductSelectDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.operation.OperationProductCourseDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.course.*;
import com.onesports.intelligent.k12.polarlight.domain.vo.product.ProductSelectByIdVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.product.ProductSelectPageVO;
import com.onesports.intelligent.k12.polarlight.security.SecurityUtils;
import com.onesports.intelligent.k12.polarlight.service.sys.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;

/**
 * @author chenrl
 **/
@Api(tags = "机构端-教务管理-商品管理")
@RestController
@RequiredArgsConstructor
@RequestMapping(ApiPathConstants.PRODUCT)
@PreAuthorize("isAuthenticated()")
public class ProductController {
    private final ProductService productService;

    @ApiOperation("添加商品信息")
    @PostMapping("/add")
    public ResponseEntity<String> add(@Json @RequestBody ProductInsertDTO productInsertDTO) {
        productInsertDTO.setOrganizationId(SecurityUtils.getOrganizationId());
        this.productService.add(productInsertDTO);
        return ResultUtil.success("添加成功!");
    }
    @ApiOperation("查询课程")
    @GetMapping("/get-course")
    public ResponseEntity<List<GetCourseVO>> getCourse() {
        return ResultUtil.success(productService.getCourse());
    }

    @ApiOperation("查询课程-修改用")
    @GetMapping("/get-course-update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "商品id", value = "productId", required = true, dataType = "long", paramType = "query")
    })
    public ResponseEntity<List<GetCourseVO>> getCourseByUpdate(String productId) {
        return ResultUtil.success(productService.getCourseByUpdate(productId));
    }
    @ApiOperation("查询校区-拼班信息-课程介绍")
    @GetMapping("/get-campus")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", value = "课程id", required = true, dataType = "long", paramType = "query")
    })
    public ResponseEntity<GetCampusIntroduceVO> getCampus(String courseId) {
        return ResultUtil.success(productService.getCampus(courseId,SecurityUtils.getOrganizationId()));
    }

    @ApiOperation("条件查询带分页")
    @GetMapping("/select-page")
    public ResponseEntity<IPage<ProductSelectPageVO>> selectPage(@Valid ProductSelectDTO productSelectDTO) {
        productSelectDTO.setOrganizationId(SecurityUtils.getOrganizationId());
        return ResultUtil.success(productService.selectPage(productSelectDTO));
    }

    @ApiOperation("根据id查看商品详情")
    @GetMapping("/select-by-id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productId", value = "商品id", required = true, dataType = "long", paramType = "query"),
    })
    public ResponseEntity<ProductSelectByIdVO> selectById(String productId) {
        return ResultUtil.success(productService.selectById(productId));
    }

    @ApiOperation("修改商品信息")
    @PostMapping("/update")
    public ResponseEntity<String> update(@Json @RequestBody ProductInsertDTO productInsertDTO) {
        this.productService.update(productInsertDTO);
        return ResultUtil.success("修改成功!");
    }

    @ApiOperation("根据id修改商品上下架状态")
    @PostMapping("/select-is-sell")
    public ResponseEntity<ProductSelectByIdVO> selectIsSell(@RequestBody ProductIsSellDTO productIsSellDTO) {
        this.productService.selectIsSell(productIsSellDTO);
        return ResultUtil.success("修改成功!");
    }

    @ApiOperation("根据id删除商品")
    @PostMapping("/delete")
    public ResponseEntity<String> delete(@RequestBody IdDTO idDTO) {
        this.productService.delete(idDTO);
        return ResultUtil.success("删除成功!");
    }
    @ApiOperation(value = "查看排课表")
    @GetMapping("/get-course-all")
    public ResponseEntity<List<CourseScheduleDetailVO>> getCourse(@Valid OperationProductCourseDTO dto) {
        return ResultUtil.success(productService.getProductCourse(dto));
    }
    @ApiOperation(value = "查看课表id与名称")
    @GetMapping("/get-course-id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "courseId", value = "课程id", required = true, dataType = "long", paramType = "query"),
    })
    public ResponseEntity<List<CourseIdAndCourseNamelVO>> getCourseId(String courseId) {
        return ResultUtil.success(productService.getCourseId(courseId));
    }
}













